<!-- Page header -->
<div class="page-header d-print-none">
    <div class="container-xl">
        <div class="row g-2 align-items-center">
            <div class="col">
                <h2 class="page-title">
                    新增板块
                </h2>
            </div>
        </div>
    </div>
</div>
<!-- Page body -->
<div class="page-body">
    <div class="container-xl">
        <div class="card">
            <div class="card-body">
                <div class="mb-3">
                    <label class="form-label"><strong>版块名</strong></label>
                    <input id="board_post_name" type="text" class="form-control" placeholder="请输入版块名">
                </div>

                <div class="mb-3">
                    <label class="form-label"><strong>排序数字</strong></label>
                    <input id="board_post_sort" type="text" class="form-control" placeholder="请输入排序数字">
                </div>

            </div>
            <div class="card-footer bg-transparent mt-auto">
                <div class="btn-list justify-content-end">
                    <a id="board_post_submit" href="javascript:void(0);" class="btn btn-primary">
                        <svg xmlns="http://www.w3.org/2000/svg" class="icon" width="24" height="24" viewBox="0 0 24 24"
                            stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round"
                            stroke-linejoin="round">
                            <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
                            <path d="M5 12l5 5l10 -10"></path>
                        </svg>
                        新增板块
                    </a>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    // ============ 管理员新增板块 ============
    $('#board_post_submit').click(function () {
        var board_post_name = $('#board_post_name').val();
        var board_post_sort = $('#board_post_sort').val();
        if (board_post_name == '') {
            // 提示信息
            $.toast({
                heading: '错误',
                text: '板块名不能为空！',
                icon: 'error'
            });
            return false;
        }
        if (board_post_sort == '') {
            // 提示信息
            $.toast({
                heading: '错误',
                text: '排序数字不能为空！',
                icon: 'error'
            });
            return false;
        }
        if (board_post_sort < 0) {
            // 提示信息
            $.toast({
                heading: '错误',
                text: '排序数字不能小于0！',
                icon: 'error'
            });
            return false;
        }

        // 发送 Ajax 请求
        $.ajax({
            url: '/admin/addBoard',
            type: 'post',
            data: {
                name: board_post_name,
                sort: board_post_sort
            },
            success: function (data) {
                if (data.code == 0) {
                    $.toast({
                        heading: '成功',
                        text: data.message,
                        icon: 'success',
                        // 以下参数根据具体Toast库调整（示例为通用方案）
                        showHideTransition: 'fade',  // 动画类型
                        hideAfter: 700,             // 显示时长（毫秒）
                        afterHidden: function () {    // 隐藏后的回调
                            // 刷新页面
                            location.reload();
                        }
                    });
                } else {
                    $.toast({
                        heading: '错误',
                        text: data.message,
                        icon: 'error'
                    });
                }
            },
            error: function () {
                // 提示信息
                $.toast({
                    heading: '错误',
                    text: '访问出现问题，请与管理员联系.',
                    icon: 'error'
                });
            }
        });
    });
</script>
</body>

</html>